package com.xln.furns.dao.impl;

import com.xln.furns.dao.MemberDAO;
import com.xln.furns.entity.Member;

public class MemberDAOimpl extends BasicDAO<Member> implements MemberDAO {

    /**
     *通过用户名返回对应的Member
     * @param username 用户名
     * @return 对应的Member ,如果没有，返回null
     */
    @Override
    public Member queryMemberByUsername(String username) {
//        先在sqlyog测试
        String sql = "SELECT `id`,`username`,`password`,`email` FROM `member`"+
                " WHERE `username`=?";

        return querySingle(sql,Member.class,username);
    }

    /**
     * 保存一个用户
     * @param member 传入Member对象
     * @return 返回就是失败，返回其他数字就是受影响的行数
     */

    @Override
    public int saveMember(Member member) {
        String sql = "INSERT INTO `member`(`username`,`password`,`email`)"+
        "VALUE (?,MD5(?),?)";
        return update(sql,member.getUsername(),member.getPassword(),member.getEmail());
    }
}
